Skip to content

feat(mappers): langfuse provider changes to support newer version of langfuse#165

Merged
poshinchen merged 2 commits intostrands-agents:mainfrom
poshinchen:feat/mappers-langfuse-change
Mar 27, 2026
Merged

feat(mappers): langfuse provider changes to support newer version of langfuse#165
poshinchen merged 2 commits intostrands-agents:mainfrom
poshinchen:feat/mappers-langfuse-change

Conversation

@poshinchen
Copy link
Copy Markdown
Contributor

@poshinchen poshinchen commented Mar 16, 2026

Description

LangfuseProvider multi-framework support

  • Makes LangfuseProvider work with traces from any framework (LangChain, Strands, LlamaIndex, CrewAI, etc.) — not just Strands.

This PR makes the provider framework-agnostic by routing on obs.type (universal across all frameworks in Langfuse) with a Strands-specific fallback for backward compatibility.

Changes

  • langfuse_provider.py — Multi-framework observation routing:
  • _convert_observation(): Route by universal obs.type (GENERATION → InferenceSpan, TOOL → ToolExecutionSpan, CHAIN/AGENT root → AgentInvocationSpan) with Strands SPAN name-based fallback preserved
  • _convert_tool_execution(): Handle both Strands format (obs.input.name) and LangChain/universal format (obs.name + obs.input as arguments)
  • _parse_tool_result(): Support LangChain ToolMessage format ({"content": "...", "type": "tool"})
  • _convert_message(): Parse LangChain tool_calls field on assistant messages
  • _extract_user_prompt(): Handle LangChain CHAIN formats ({"input": "..."}, {"messages": [...]}) and Strands message-list format via OTEL ([{"role": "user", "content": '[{"text": "..."}]'}])
  • _extract_agent_response(): Handle LangChain CHAIN output formats ({"output": "..."}, {"messages": [...]}) and Strands message-list output format
  • _extract_text_from_content(): New helper to unwrap Strands content (plain string, JSON-encoded [{"text": "..."}], or parsed list)
  • pyproject.toml: Cap langfuse dependency at <4

Related Issues

#91
#159

Documentation PR

N/A

Type of Change

New feature

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 908985f to 51db383 Compare March 23, 2026 00:26
@poshinchen poshinchen changed the title Feat/mappers langfuse change feat(mappers) Feat/mappers langfuse change to support newer version of langfuse Mar 23, 2026
@poshinchen poshinchen changed the title feat(mappers) Feat/mappers langfuse change to support newer version of langfuse feat(mappers): Feat/mappers langfuse change to support newer version of langfuse Mar 23, 2026
@poshinchen poshinchen changed the title feat(mappers): Feat/mappers langfuse change to support newer version of langfuse feat(mappers): langfuse provider changes to support newer version of langfuse Mar 23, 2026
@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 51db383 to 5f71df9 Compare March 26, 2026 17:31
@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 5f71df9 to 4b82389 Compare March 26, 2026 17:55
@poshinchen poshinchen force-pushed the feat/mappers-langfuse-change branch from 4b82389 to b7c3b1b Compare March 26, 2026 18:25
@poshinchen poshinchen merged commit 5067a5b into strands-agents:main Mar 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants